package ar.pmt.vista.exception;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ExceptionHandler;
import org.apache.struts.config.ExceptionConfig;

public class CustomExceptionHandler extends ExceptionHandler {

	/**
	 * Handle the exception. Standard execute method with addition of logging
	 * the stacktrace.
	 */
	public ActionForward execute(Exception ex, ExceptionConfig ae,
			ActionMapping mapping, ActionForm formInstance,
			HttpServletRequest request, HttpServletResponse response)
			throws ServletException {

		//Loggeamos el error en los archivos de logs
		PlatformException.logError(ex);

		//Mostramos el error por el SystemOut
		//PlatformException.showError(ex);
		
    	request.setAttribute("errorMsg", ex.getMessage());
    	request.setAttribute("errorStack", PlatformException.toArrayList(ex));		
		
		return super.execute(ex, ae, mapping, formInstance, request, response);
	}

}